

use "$data/survey1_clean.dta", clear

gen age_35 = (age<=2)*100
gen age_45 = (age>3)*100
gen high_trust_science=(trust_science==4) *100

foreach x in male highschool college working unemp student democrat republican{
replace `x' =`x'*100
}

**** Summary stastistics of knowledge ****
gen empt=.
label var empt " "
gen demographics=. 
label var demographics "\underline{Demographics}" 
label var male "\% Male"
label var age_35 "\% Age < 35"
label var age_45 "Age > 44"
label var highschool "\% Highschool education"
label var college "\% College eductation"
label var working "\% Currently working"
label var unemp "Unemployed"
label var student "Student"
label var democrat "\% Democrat"
label var republican "\% Republican"
label var high_trust_science "\% High trust in science"




tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 6

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear

foreach yvar of varlist male age_35  highschool college working democrat republican high_trust_science empt{

	sum `yvar', d
	if `r(N)'!=0 {
	sum `yvar' if highmortality==0, d
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	sum `yvar' if highmortality==1, d
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col2
	reg `yvar' highmortality, r
	test highmortality
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col3

	sum `yvar' if contagiontreatment==0, d
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col4
	sum `yvar' if contagiontreatment==1, d
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col5
	reg `yvar' contagiontreatment, r
	test contagiontreatment
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col6
	
	
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}

*** Last column 	
	local varlabels "`varlabels' "p-value of joint significance" "
	loc statnames "`statnames' thisstat`count'"

reg highmortality male age_35 highschool college working  democrat republican high_trust_science , r
test male age_35  highschool college working  democrat republican high_trust_science 
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col3
reg contagiontreatment male age_35 highschool college working  democrat republican high_trust_science , r
test male age_35  highschool college working democrat republican high_trust_science 
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col6


/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"


esttab col* using "$tables/balance_experiment_main", booktabs cells(none) nogap mtitle("Mean low rel. mortality" "Mean high rel. mortality" "p(low rel. mort. = high rel. mort)" ///
"Mean no contagion info" "Mean contagion info" "p(no info = info)") ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace ///
 mgroups("Mortality information experiment" "Contagion information experiment",  pattern(1 0 0 1 0 0   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))



eststo clear
